package dk.mirasola.systemtraining.bridgewidgets.shared.factory;


import dk.mirasola.systemtraining.bridgewidgets.shared.model.Seat;

public class SeatFactory {
    public static String seatToString(Seat seat) {
        if (seat == null) {
            throw new NullPointerException();
        }

        switch (seat) {
            case NORTH:
                return "N";
            case EAST:
                return "E";
            case SOUTH:
                return "S";
            case WEST:
                return "W";
            default:
                throw new RuntimeException("Unknow seat: " + seat);
        }
    }

    public static Seat stringToSeat(String encodedStr) {
        if (encodedStr == null) {
            throw new NullPointerException();
        } else if (encodedStr.length() == 1) {
            if ("N".equals(encodedStr)) {
                return Seat.NORTH;
            } else if ("E".equals(encodedStr)) {
                return Seat.EAST;
            } else if ("S".equals(encodedStr)) {
                return Seat.SOUTH;
            } else if ("W".equals(encodedStr)) {
                return Seat.WEST;
            } else {
                throw new RuntimeException("Cannot parse '" + encodedStr + "' to seat");
            }
        } else {
            throw new RuntimeException("Cannot parse '" + encodedStr + "' to seat");
        }
    }

    public static Seat charToSeat(char c) {
        if ('N' == c) {
            return Seat.NORTH;
        } else if ('E' == c) {
            return Seat.EAST;
        } else if ('S' == c) {
            return Seat.SOUTH;
        } else if ('W' == c) {
            return Seat.WEST;
        } else {
            throw new RuntimeException("Cannot parse '" + c + "' to seat");
        }
    }

    private SeatFactory() {
    }

}
